package com.castle.fortress.admin.pay.enums;


import com.castle.fortress.common.exception.BizException;
import com.castle.fortress.common.respcode.BizErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 支付方式
 * @author castle
 */
@Getter
@AllArgsConstructor
public enum PayTypeEnum {

    ALIPAY_APP("ALIPAY_APP", PayPlatformEnum.ALIPAY, "支付宝APP支付"),

    ALIPAY_MINI("ALIPAY_MINI", PayPlatformEnum.ALIPAY, "支付宝小程序支付"),

    ALIPAY_PC("ALIPAY_PC", PayPlatformEnum.ALIPAY, "支付宝PC支付"),

    ALIPAY_WAP("ALIPAY_WAP", PayPlatformEnum.ALIPAY, "支付宝手机网站支付"),

    WXPAY_JSAPI("WXPAY_JSAPI", PayPlatformEnum.WX, "微信公众号支付"),

    WXPAY_H5("WXPAY_H5", PayPlatformEnum.WX, "微信H5支付"),

    WXPAY_NATIVE("WXPAY_NATIVE", PayPlatformEnum.WX, "微信Native支付"),

    WXPAY_MINI("WXPAY_MINI", PayPlatformEnum.WX, "微信小程序支付"),

    WXPAY_APP("WXPAY_APP", PayPlatformEnum.WX, "微信APP支付"),
    ;

    private String code;

    private PayPlatformEnum platform;

    private String desc;

    public static PayTypeEnum getByName(String name) {
        for (PayTypeEnum payTypeEnum : PayTypeEnum.values()) {
            if (payTypeEnum.name().equalsIgnoreCase(name)) {
                return payTypeEnum;
            }
        }
        throw new BizException(BizErrorCode.PAY_TYPE_ERROR);
    }

    public static PayTypeEnum getByCode(String code) {
        for (PayTypeEnum payTypeEnum : PayTypeEnum.values()) {
            if (payTypeEnum.getCode().equalsIgnoreCase(code)) {
                return payTypeEnum;
            }
        }
        throw new BizException(BizErrorCode.PAY_TYPE_ERROR);
    }
}
